//
//  GRAllBillTableViewCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/27.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRAllBillTableViewCell.h"

@implementation GRAllBillTableViewCell


-(GRBlankSpace *)blankSpceView{
    
    if (!_blankSpceView) {
        _blankSpceView = [GRBlankSpace xx_instantiateFromNib];
        _blankSpceView.contentMode = GRBlankContentModeEmptyOrders;
        _blankSpceView.frame = CGRectMake(15, 45, self.contentView.bounds.size.width-30, self.contentView.bounds.size.height-45);
        [self.contentView addSubview:_blankSpceView];
      
    }
    return _blankSpceView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.backgroundView.hidden = YES;
    [self.monthLabel sizeToFit];
}

-(void)setBillModel:(GRAllBillModel *)billModel{
    _billModel = billModel;
    self.monthLabel.text = billModel.monthCN;
  
    if (billModel.isOverdue && billModel.status == 0) {
        self.rightOffset.constant = 33;
        self.warningImageView.hidden = NO;
        self.statusLabel.text = @"逾期";
        self.statusLabel.textColor = HEXCOLOR(0xE5004F);
        self.priceLabel.text = [NSString stringWithFormat:@"%.2lf",billModel.totalPrice];
    }else{
        self.rightOffset.constant = 9;
        self.warningImageView.hidden = YES;
        if (billModel.status == 0) {//待还款
            self.statusLabel.textColor = HEXCOLOR(0xE5004F);
            if (![billModel.subDay isEqualToString:@"<null>"]&&billModel.subDay != nil) {
                self.statusLabel.text = [NSString stringWithFormat:@"还剩%@天到还款日",billModel.subDay];
                
            }else{
                self.statusLabel.textColor = HEXCOLOR(0x999999);
                self.statusLabel.text = @"去还款";
            }
            NSString * priceTex = [NSString stringWithFormat:@"%.2lf\n剩余%.2lf待还",billModel.totalPrice,billModel.price] ;
          NSRange priceRange =  [priceTex rangeOfString:[NSString stringWithFormat:@"剩余%.2lf待还",billModel.price]];
            NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc]initWithString:priceTex attributes: @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:HEXCOLOR(0x222222)}];
            [attribute setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:HEXCOLOR(0x999999)} range:priceRange];
          
            self.priceLabel.attributedText = attribute;
        }else{
            self.statusLabel.text = @"已还清";
            self.priceLabel.text = [NSString stringWithFormat:@"%.2lf",billModel.totalPrice];
            self.statusLabel.textColor = HEXCOLOR(0x999999);
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
